var utils = require('../../../util/utils');

const {
    increaseInvite,
    increaseFriendsReward,
    increasePersonalReward,
    increaseGrandSonReward,
    increaseMoneyReward,
    increaseUserTotalVideo,
    increaseValidUserAction
} = require('../lib/action');

module.exports = function (app) {
    return new Handler(app);
};
var Handler = function (app) {
    this.app = app;
};
var handler = Handler.prototype;

/**
 * 用户日常任务邀请奖励次数增加
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseInviteReward = async function (parent_id, uid, frontendId, cb) {
    var self = this;

    try {
        await increaseInvite.call(self, parent_id, uid);
    } catch (err) {
        console.error('increaseInviteReward err 1: ' + err);
    }

    utils.invokeCallback(cb);
};

/**
 * 用户日常任务徒弟观看视频领奖次数增加
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseFriendVideoReward = async function (uid, frontendId, cb) {
    let self = this;

    try {
        await increaseFriendsReward.call(self, uid);
    } catch (err) {
        console.error('increaseFriendVideoReward err 1: ' + err);
    }

    utils.invokeCallback(cb);
}

/**
 * 用户日常任务徒孙观看视频领奖次数增加
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseGrandSonVideoReward = async function (uid, frontendId, cb) {
    var self = this;

    try {
        await increaseGrandSonReward.call(self, uid);
    } catch (err) {
        console.error('increaseGrandSonVideoReward err 1: ' + err);
    }

    utils.invokeCallback(cb);
}

/**
 * 将日常任务的用户个人视频奖励更新为带领取状态
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increasePersonalVideoReward = async function (uid, frontendId, cb) {
    var self = this;

    try {
        await increasePersonalReward.call(self, uid);
    } catch (err) {
        console.error('increasePersonalVideoReward err 1: ' + err);
    }

    utils.invokeCallback(cb);
}

/**
 * 将日常任务的奖励金任务更新为待领取状态
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseMoneyVideoReward = async function (uid, frontendId, cb) {
    let self = this;

    try {
        await increaseMoneyReward.call(self, uid);
    } catch (err) {
        console.error('increaseMoneyVideoReward err 1: ' + err);
    }

    utils.invokeCallback(cb);
}

/**
 * 增加用户的总视频次数
 * @param uid
 * @param frontendId
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseUserTotalVideo = async function (uid, frontendId, cb) {
    let self = this;

    try {
        await increaseUserTotalVideo.call(self, uid);
    } catch (err) {
        console.error('increaseUserTotalVideo err 1: ' + err);
    }

    utils.invokeCallback(cb);
}

/**
 * 增加用户的有效徒弟数量
 * @param parent_id
 * @param uid
 * @param cb
 * @returns {Promise<void>}
 */
handler.increaseValidSon = async function (parent_id, uid, frontendId, cb) {
    let self = this;

    try {
        await increaseValidUserAction.call(self, parent_id, uid);
    } catch (err) {
        console.error('increaseValidSon err 1: ' + err);
    }
    utils.invokeCallback(cb);
}

